# Maintainer: Filipe Laíns (FFY00) <filipe.lains@gmail.com>
# Contributor: Michal Krenek (Mikos) <m.krenek@gmail.com>

pkgname=dsdcc
pkgver=1.9.4
pkgrel=1
pkgdesc='Digital Speech Decoder (DSD) rewritten as a C++ library'
arch=('loong64' 'x86_64')
url='https://github.com/f4exb/dsdcc'
license=('GPL3')
depends=('mbelib' 'serialdv')
makedepends=('cmake')
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha512sums=('6724ddb867b4664026b1a5f1e004fbd5f57ee0b6e7c7669a83b273a26b362d29d61e7ac16d8908205836f07d413cf1a8808472db84c83f27c7809fc88753309e')

prepare() {
  cd $pkgname-$pkgver

  sed -i 's|LIBSERIAL_NAMES|LIBSERIALDV_NAMES|g' cmake/Modules/FindSerialDV.cmake
}

build() {
  mkdir -p "$srcdir"/$pkgname-$pkgver/build
  cd "$srcdir"/$pkgname-$pkgver/build

  cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DLIBSERIALDV_INCLUDE_DIR=/usr/include/serialdv \
    -DUSE_MBELIB=ON

  make

  # Build tests
  cd "$srcdir"/$pkgname-$pkgver/testfec

  make
}

check() {
  cd $pkgname-$pkgver/testfec

  ./qr
  ./golay20
  ./golay23
  ./golay24
  ./hamming7
  ./hamming12
  ./hamming15
  ./hamming16
  ./viterbi
  ./viterbi35
  ./crc
}

package() {
  cd $pkgname-$pkgver/build

  make DESTDIR="$pkgdir" install
}

